//
//  SignsViewController.m
//  MerieuxWskProj
//
//  Created by MacBook Pro on 16/8/5.
//  Copyright © 2016年 visionet. All rights reserved.
//

#import "SignsViewController.h"
#import "TouchView.h"
#import "BorderButton.h"
#import "DevicePrepaireReportViewController.h"

@interface SignsViewController ()
@property (weak, nonatomic) IBOutlet TouchView *signView;
@property(nonatomic,retain)UIImage *img;

@end

@implementation SignsViewController
- (IBAction)saveClick:(BorderButton *)sender {
    if (self) {
        
        if (self.block) {
            //3,  调用 执行（把文本框的内容作为参数 传回），回调了（3）
            self.block([self snapshot:self.signView]);
            [self.navigationController  popViewControllerAnimated:YES ];
            
        }
        
    }
    
     [self dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)cancelClick:(BorderButton *)sender {
    
    if (self) {
        if (self.isBtn) {
            self.isBtn(NO);
            [self.navigationController popViewControllerAnimated:YES];
        }
    }
    [self dismissViewControllerAnimated:YES completion:nil];
    
}
- (IBAction)reDrawClick:(BorderButton *)sender {
    
   [self.signView clearScreen];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

#pragma mark - Private method
//截图
- (UIImage *)snapshot:(UIView *)view
{
    NSLog(@"截图");
    UIGraphicsBeginImageContextWithOptions(view.bounds.size,YES,0);
    
    //[view drawHierarchyInRect:view.bounds afterScreenUpdates:YES];
    [view drawViewHierarchyInRect:view.bounds afterScreenUpdates:YES];
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    return image;
    
}

//支持旋转
-(BOOL)shouldAutorotate{
    return YES;
}
//
//支持的方向
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscapeLeft;
}

//一开始的方向  很重要
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
    return UIInterfaceOrientationLandscapeLeft;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
